package com.wang.learn.cloudiot.controller;

import com.wang.learn.cloudiot.model.po.Pile;
import com.wang.learn.cloudiot.service.PileService;
import com.wang.learn.cloudiot.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author Chen Nan
 */
@Slf4j
@RestController
@RequestMapping("/jdbc")
public class JdbcController {

    @Autowired
    private PileService pileService;

    @Autowired
    private TestService testService;

    @PostMapping("/insert")
    public Integer insert(@RequestBody Pile pile) {
        return pileService.insertPile(pile);
    }

    @GetMapping("/list")
    public Integer list(Pile pile) {
        List<Pile> list = pileService.list(pile);
        log.info("list size:[{}]", list.size());
        return list.size();
    }

    @PostMapping("/update")
    public Integer update(@RequestBody Pile pile) {
        return pileService.update(pile);
    }

    @GetMapping("/delete")
    public Integer test() {
        return pileService.deleteAll(new Date());
    }

    @GetMapping("/test")
    public Long test(int num) throws InterruptedException {
        return testService.batchInsert(num);
    }

}
